<template>
	<view class="container" style="padding-bottom: 140rpx;">
		<view class="headView" @click="headViewTap">
			<view style="display: flex;flex-direction: row;align-items: center;justify-content: space-between;">
				<view style="display: flex;flex-direction: row;align-items: center;">
					<image class="headImgView" :src="shopInfo.coverUrl||userInfo.avatarUrl"
					 mode="aspectFill"></image>
					<view class="content">
						<view class="nickname uni-title-h2">{{shopInfo.name || userInfo.nickname || '未设置'}}</view>
						<!-- <view class="phone" v-if="userInfo.parentModel.code">推广码：{{userInfo.code}}</view> -->
						<view class="phone" style="margin-top: 10rpx;font-size: 26rpx;">{{shopInfo.addr||userInfo.phone}}</view>
						<!-- <view class="phone" v-else @click.stop="scanAction"><text style="margin-right: 30rpx;">扫码绑定推广人</text><u-icon name="scan" size='40rpx'></u-icon></view> -->
						<!-- <view class="phone">红娘身份：{{userInfo.rankModel.name}}</view> -->
					</view>
				</view>
				<view style="flex-shrink: 0;margin-right: 20rpx;margin-left: 16rpx;">
					<u-icon name="arrow-right" color="#FFF" size="15"></u-icon>
				</view>
			</view>
			<!-- 二维码 -->
			<!-- <view @click.stop="scanAction" style="position: absolute;top: 100rpx;right: 20rpx;"><u-icon name="scan" size='80rpx' color='#FFF'></u-icon></view> -->
			<!-- 数据统计 -->
			<view class="loveCate">
				<view class="item" @click.stop="waitSendAction">
					<text style="font-size: 36rpx;font-weight: bold;">{{shopInfo.ordersForWaitSendNum||0}}</text>
					<text>待发货订单</text>
				</view>
				<view class="item" @click.stop="goWallet">
					<text style="font-size: 36rpx;font-weight: bold;">{{shopInfo.totalOrderMoney||0}}</text>
					<text>今日业绩（元）</text>
				</view>
			</view>
		</view>
		<!-- 分类 -->
		<view v-for="(obj, inx) in itemList" :key='inx'
		style="width: 710rpx;padding: 0 20rpx;background-color: #FFFFFF;margin-top: 30rpx;">
			<view style="width: 670rpx;height: 100rpx;line-height: 100rpx;margin-left: 20rpx;border-bottom: 1px solid #eeeeee;">{{obj.title}}</view>
			<view style="display: flex;flex-direction: row;flex-wrap: wrap;justify-content: flex-start;">
				<view v-for="(item, index) in obj.items" :key="index" @click="itemTap(item, index)"
				style="width: 177rpx;display: flex;flex-direction: column;align-items: center;">
					<u-icon :customStyle="{paddingTop:30+'rpx'}" :name="item.icon" size="30" :color='item.color'></u-icon>
					<text style="margin-top: 12rpx;margin-bottom: 20rpx;font-size: 26rpx;">{{item.title}}</text>
				</view>
			</view>
		</view>
		<u-modal :show="uModalShow" @confirm="confirmCancelCoupon" @cancel='uModalShow=false' confirmText='确认核销' showCancelButton='true' :content='uModalContent' :asyncClose="true">
			<view class="slot-content">
				<view style="padding: 40rpx 0;">
					<view style="font-size: 36rpx;">优惠券名称：{{couponModel.name}}</view>
					<view style="font-size: 36rpx;" v-if="couponModel.userModel">兑换人手机号：{{couponModel.userModel.phone}}</view>
					<view style="font-size: 32rpx;margin-top: 16rpx;">内容：{{couponModel.content}}</view>
				</view>
			</view>
		</u-modal>
	</view>
</template>

<script>
	import {
		common
	} from '@/api/common.js'
	import {
		shop
	} from '@/api/shop.js'
	import {
		coupon
	} from '@/api/coupon.js'
	import {
		merchant
	} from '@/api/merchant.js'

	import {
		page
	} from '@/api/page.js'
	import {toLogin} from '@/router/index.js';
	import {wxminiproPay} from '@/common/utils/wxminiproPay.js'
	export default {
		components: {
		},
		data() {
			return {
				shopInfo: {},
				userInfo: {},
				uModalShow: false,
				couponModel: {},
				itemList: [
					{
						title: '门店管理',
						items: [
							// {
							// 	title: "扫码核销",
							// 	icon: 'scan',
							// 	color: '#2979ff',
							// 	name: 'scanExchange',
							// 	value: '',
							// 	params: {
							// 	}
							// },
							// {
							// 	title: "输码核销",
							// 	icon: 'edit-pen',
							// 	color: '#ff8526',
							// 	name: 'inputExchange',
							// 	value: '',
							// 	params: {
							// 	}
							// },
							// {
							// 	title: "核销记录",
							// 	icon: 'list',
							// 	color: '#666',
							// 	name: 'cancelRecord',
							// 	value: '',
							// 	params: {
							// 	}
							// },
							// {
							// 	title: "发布优惠券",
							// 	icon: 'coupon',
							// 	color: '#b47f0f',
							// 	name: 'publicCoupon',
							// 	value: '',
							// 	params: {
							// 	}
							// },
							// {
							// 	title: "我的店铺码",
							// 	icon: 'download',
							// 	color: '#ba540d',
							// 	name: 'shopQrcode',
							// 	value: '',
							// 	params: {
							// 	}
							// },
							{
								title: "店铺收款码",
								icon: 'rmb-circle',
								color: '#fa3534',
								name: 'shopReceivingQrcode',
								value: '',
								params: {
								}
							},
							{
								title: "商品管理",
								icon: 'shopping-cart',
								color: '#0058f0',
								name: 'itemForM',
								value: '',
								params: {
								}
							},
						],
					},
					{
						title: '门店订单', 
						items: [
							{
								title: "待付款",
								name: 'orderListForShop',
								icon: '/static/common/mine/wait_pay.png',
								iconColor: '#FC5E53',
								value: '',
								params: {
									current: '0',
								}
							},
							{
								title: "待发货",
								name: 'orderListForShop',
								icon: '/static/common/mine/wait_send.png',
								iconColor: '#FC5E53',
								value: '',
								params: {
									current: '1',
								}
							},
							{
								title: "待收货",
								name: 'orderListForShop',
								icon: '/static/common/mine/wait_delivery.png',
								iconColor: '#FC5E53',
								value: '',
								params: {
									current: '2',
								}
							},
							{
								title: "已完成",
								name: 'orderListForShop',
								icon: '/static/common/mine/finish.png',
								iconColor: '#d0541c',
								value: '',
								params: {
									current: '3',
								}
							}
						],
					},
					{
						title: '财务管理', 
						items: [
							{
								title: "我的钱包",
								icon: 'rmb-circle-fill',
								color: '#ff9014',
								name: 'wallet',
								value: ''
							},
						]
					}
				]
			}
		},
		onLoad() {
			this.userInfo = this.$storage.getStorageDataSync(this.$store.state.userInfo)
			if(this.$Route.query.CHN && this.$Route.query.CHN == 'coupon' ){
				this.couponModel.code = this.$Route.query.qrcode
				this.confirmCancelCoupon()
			}
		},
		onShow() {
			this.loadData()
		},
		onPullDownRefresh() {
			this.loadData()
		},
		onShareAppMessage(res) {
			return {
				title: '',
				path: this.$Route.path
			}
		},
		methods: {
			loadData() {
				this.getShopInfoForUserId()
			},
			headViewTap(){
				this.$Router.push({
					name: 'updateShop',
					params: {
						shopId: this.shopInfo.id
					}
				})
			},
			itemTap(item, index) {
				var names = ['shop', 'shopQrcode', 'shopReceivingQrcode', 'publicCoupon', 'cancelRecord', 'itemForM', 'orderListForShop']
				var params = item.params || {}
				if (names.indexOf(item.name) != -1){
					if(this.shopInfo.id) {
						params.shopId = this.shopInfo.id
						params.shopName = this.shopInfo.name
					}else{
						return
					}
				}else if(item.name == 'scanExchange'){
					var _this = this
					uni.scanCode({
						success: function (res) {
							console.log('条码类型：' + res.scanType);
							console.log('条码内容：' + res.result );
							var result = _this.$tools.urlParmasToObj(res.result)
							if(result){
								coupon.checkCoupon({
									code: result.qrcode,
								}).then(res => {
									if (res.data.code == 10000) {
										_this.uModalShow = true
										_this.couponModel = res.data.data
									}
								})
							}
						}
					});
					
					return
				}
				this.$Router.push({
					name: item.name,
					params: params
				})
			},
			confirmCancelCoupon(){
				coupon.cancelCoupon({
					// CHN: result.CHN,
					code: this.couponModel.code,
					cancelType: '1'
				}).then(res => {
					if (res.data.code == 10000) {
						this.uModalShow = false
						uni.showToast({
							title: '核销成功',
							icon: 'success',
							duration: 2000
						})
					}
				})
			},
			waitSendAction(){
				this.$Router.push({
					name: 'orderListForShop',
					params: {
						current: '1',
					}
				})
			},
			getShopInfoForUserId() {
				shop.getShopInfoForUserId({
					userId: this.userInfo.id
				}).then(res => {
					uni.stopPullDownRefresh();
					if (res.data.code == 10000) {
						this.shopInfo = res.data.data

					}
				})
			},
			goWallet(){
				this.$Router.push({
					name: 'wallet'
				})
			},
		},
	}
</script>

<style lang="scss" scoped>
	.container {
		margin-bottom: 60rpx;
	}
	.headView {
		width: 710rpx;
		height: 320rpx;
		padding-top: 30rpx;
		margin-left: 20rpx;
		display: flex;
		flex-direction: column;
		border-radius: 30rpx;
		background-image: linear-gradient(-90deg, #2c84f8, #4473ff);

		.headImgView {
			margin-top: 30rpx;
			margin-left: 20rpx;
			width: 140rpx;
			height: 140rpx;
			border-radius: 70rpx;
		}

		.content {
			margin-left: 18px;
			margin-top: 30rpx;
			display: flex;
			flex-direction: column;
			width: 100%;
			.nickname {
				font-size: 34rpx;
				color: #FFFFFF;
			}

			.phone {
				color: #FFFFFF;
				font-size: 26rpx;
				display: flex;
				flex-direction: row;
				align-items: center;
			}
		}

		.login {
			margin-top: 40rpx;
			margin-left: 40rpx;
		}
	}

	.main {
		position: relative;
		top: -60rpx;
	}

	.loveCate {
		display: flex;
		flex-direction: row;
		align-items: center;
		width: 710rpx;
		height: 160rpx;
		border-radius: 14rpx;
		margin-left: 20rpx;

		.item {
			display: flex;
			flex-direction: column;
			align-items: center;
			width: 375rpx;
			font-size: 28rpx;
			position: relative;
			color: #FFFFFF;
		}
	}

	// 订单
	.orderView{
		background-color: #FFFFFF;
		width: 710rpx;
		margin-top: 20rpx;
		margin-left: 20rpx;
		border-radius: 14rpx;
		padding: 30rpx 0rpx;

		.title {
			margin: 0 30rpx;
			padding-bottom: 10rpx;
			font-weight: bold;
			border-bottom: 1px solid #eeeeee;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: space-between;
		}

		.orderCate {
			display: flex;
			flex-direction: row;
			align-items: center;
			margin-top: 30rpx;
			margin-bottom: 20rpx;

			.item {
				display: flex;
				flex-direction: column;
				align-items: center;
				width: 162.5rpx;
				margin-left: 20rpx;
				border-radius: 20rpx;
				position: relative;

				text {
					margin-top: 16rpx;
				}
			}
		}
	}
	// 会员服务
	.serviceView{
		background-color: #FFFFFF;
		width: 710rpx;
		margin-top: 20rpx;
		margin-left: 20rpx;
		border-radius: 14rpx;
		padding: 20rpx 0;
		display: flex;
		flex-direction: row;
		.serviceCate{
			width: 100%;
			.grid-text {
				font-size: 14px;
				color: #333;
				padding: 14rpx 0 20rpx 0rpx;
				/* #ifndef APP-PLUS */
				box-sizing: border-box;
				/* #endif */
			}
		}
	}

	.itemList {
		margin-top: 20rpx;
		margin-left: 20rpx;
		width: 710rpx;
		background-color: #FFFFFF;
	}
	.bagShopCenter {
		width: 160rpx;
		height: 64rpx;
		line-height: 64rpx;
		margin-right: 50rpx;
		text-align: center;
		background-color: red;
		color: #FFFFFF;
		font-size: 26rpx;
		border-radius: 32rpx;
		position: relative;
		right: -20rpx;
		
	}
</style>
